package org.example.demo21.chain;

import org.example.demo21.chain.interfaces.Filter;
import org.example.demo21.entity.bo.DemoBO;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author guocong
 * @since 2024/3/29 11:48
 */
public class ChainFilter implements Filter {

    List<Filter> filters = new ArrayList<>();

    /**
     * 定义责任链
     * @param filter 过滤器
     * @return chainFilter
     */
    public ChainFilter add(Filter filter) {
        filters.add(filter);
        return this;
    }


    @Override
    public boolean doFilter(DemoBO demoBO) {
        for (Filter filter : filters) {
            if (!filter.doFilter(demoBO)) {
                return false;
            }
        }
        return true;
    }
}
